<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>卫星绕地球匀速圆周运动模拟器</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #1a2a6c, #2c3e50);
            color: #fff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            padding: 20px;
        }
        
        .header {
            text-align: center;
            padding: 20px 0;
            margin-bottom: 20px;
        }
        
        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            background: linear-gradient(to right, #4facfe, #00f2fe);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        
        .container {
            display: flex;
            flex-wrap: wrap;
            max-width: 1200px;
            margin: 0 auto;
            gap: 30px;
        }
        
        .animation-container {
            flex: 1;
            min-width: 500px;
            background: rgba(0, 10, 30, 0.7);
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            flex-direction: column;
        }
        
        .canvas-wrapper {
            position: relative;
            width: 100%;
            height: 400px;
            background: #0a1929;
            border-radius: 15px;
            overflow: hidden;
            border: 1px solid rgba(0, 195, 255, 0.3);
            box-shadow: 0 0 20px rgba(0, 150, 255, 0.2);
        }
        
        canvas {
            width: 100%;
            height: 100%;
        }
        
        .controls {
            flex: 1;
            min-width: 300px;
            background: rgba(0, 10, 30, 0.7);
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .control-group {
            margin-bottom: 30px;
        }
        
        h2 {
            margin-bottom: 20px;
            color: #4facfe;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .slider-container {
            display: flex;
            align-items: center;
            gap: 15px;
            margin-bottom: 20px;
        }
        
        .slider-container label {
            min-width: 120px;
            font-weight: bold;
            color: #00f2fe;
        }
        
        .slider-container input {
            flex: 1;
            height: 8px;
            -webkit-appearance: none;
            background: linear-gradient(to right, #4facfe, #00f2fe);
            border-radius: 10px;
            outline: none;
        }
        
        .slider-container input::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            background: #fff;
            cursor: pointer;
            box-shadow: 0 0 10px rgba(0, 150, 255, 0.8);
        }
        
        .value-display {
            font-size: 1.2rem;
            font-weight: bold;
            color: #00f2fe;
            text-align: center;
            padding: 10px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 10px;
            margin-top: 5px;
        }
        
        .physics-section {
            background: rgba(0, 30, 60, 0.5);
            border-radius: 15px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .formula {
            font-size: 1.4rem;
            text-align: center;
            margin: 15px 0;
            padding: 15px;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            font-family: 'Courier New', monospace;
            color: #4facfe;
        }
        
        .result {
            display: flex;
            justify-content: space-around;
            margin-top: 20px;
            flex-wrap: wrap;
            gap: 15px;
        }
        
        .result-box {
            background: rgba(0, 0, 0, 0.3);
            border-radius: 15px;
            padding: 20px;
            text-align: center;
            flex: 1;
            min-width: 150px;
            border: 1px solid rgba(0, 195, 255, 0.3);
        }
        
        .result-value {
            font-size: 1.8rem;
            font-weight: bold;
            color: #00f2fe;
            margin-top: 10px;
        }
        
        .unit {
            font-size: 0.9rem;
            color: #aaa;
        }
        
        .info-panel {
            background: rgba(0, 30, 60, 0.5);
            border-radius: 15px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .info-panel ul {
            padding-left: 20px;
            margin-top: 10px;
        }
        
        .info-panel li {
            margin-bottom: 8px;
            line-height: 1.5;
        }
        
        .footer {
            text-align: center;
            margin-top: 30px;
            padding: 20px;
            color: rgba(255, 255, 255, 0.6);
            font-size: 0.9rem;
        }
        
        @media (max-width: 900px) {
            .container {
                flex-direction: column;
            }
            
            .animation-container, .controls {
                min-width: 100%;
            }
        }
        
        .stars {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
        }
        
        .star {
            position: absolute;
            background: white;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1><i class="fas fa-satellite"></i> 卫星绕地球匀速圆周运动模拟器</h1>
        <p>探索万有引力与向心力如何维持卫星轨道运动</p>
    </div>
    
    <div class="container">
        <div class="animation-container">
            <h2><i class="fas fa-globe-americas"></i> 轨道模拟</h2>
            <div class="canvas-wrapper">
                <div class="stars" id="stars"></div>
                <canvas id="orbitCanvas"></canvas>
            </div>
            <div class="info-panel">
                <p><i class="fas fa-info-circle"></i> 此模拟展示了卫星在万有引力作用下绕地球做匀速圆周运动。调整轨道半径可观察速度与周期的变化。</p>
            </div>
        </div>
        
        <div class="controls">
            <div class="control-group">
                <h2><i class="fas fa-sliders-h"></i> 轨道控制</h2>
                <div class="slider-container">
                    <label for="radiusSlider">轨道半径：</label>
                    <input type="range" id="radiusSlider" min="1" max="10" step="0.1" value="2">
                </div>
                <div class="value-display">
                    当前轨道半径：<span id="altitudeValue">12740 km</span> （<span id="radiusValue2">2.0</span>倍地球半径）
                </div>
            </div>
            
            
            <div class="control-group">
                <h2><i class="fa fa-info-circle"></i> 轨道信息</h2>

                <div class="result">
                    <div class="result-box">
                        <div>轨道速度</div>
                        <div class="result-value" id="velocity">7.78</div>
                        <div class="unit">km/s</div>
                    </div>
                    <div class="result-box">
                        <div>运行周期</div>
                        <div class="result-value" id="period">1.61</div>
                        <div class="unit">小时</div>
                    </div>
                </div>
            </div>
            
            
            <div class="control-group">
                <h2><i class="fas fa-atom"></i> 物理原理</h2>
                <p>万有引力公式为</p>
                <div class="formula">
                    F = G · M · m / R²
                </div>
                <p>向心力公式为</p>
                <div class="formula">
                    F = m · v² / R
                </div>
                <p>卫星绕地球运动所需的向心力由万有引力提供，因此：</p>
                <div class="formula">
                    F = G · M · m / R² = m · v² / R
                </div>
                <p>即：</p>
                 <div class="formula">
                    v = √(G · M / R)
                </div>
                <div class="formula">
                    T = 2πR / v
                </div>
            </div>
            
            <div class="control-group">
                <h2><i class="fas fa-lightbulb"></i> 科学知识</h2>
                <ul>
                    <li>地球半径 R = 6,370 km （近似），质量 M = 5.97×10²⁴ kg （近似）</li>
                    <li>万有引力常数 G = 6.67430×10⁻¹¹ m³kg⁻¹s⁻² （近似）</li>
                    <li>近地轨道(LEO)高度约200-2,000 km</li>
                    <li>地球同步轨道(GEO)高度约35,786 km</li>
                    <li>国际空间站轨道高度约400 km，速度约7.66 km/s</li>
                </ul>
            </div>
        </div>
    </div>
    
    <div class="footer">
        <p>轨道模拟画图并非真实比例。本页面由AI辅助创建，仅供参考，不构成专业建议</p>
    </div>

    <script>
        // 获取Canvas和上下文
        const canvas = document.getElementById('orbitCanvas');
        const ctx = canvas.getContext('2d');
        
        // 设置Canvas尺寸
        function setupCanvas() {
            const container = canvas.parentElement;
            canvas.width = container.clientWidth;
            canvas.height = container.clientHeight;
        }
        
        // 初始设置
        setupCanvas();
        window.addEventListener('resize', setupCanvas);
        
        // 物理常量
        const GM = 3.98e5; //(km³ s⁻²)
        const R_earth = 6370;      // 地球半径 (km)
        
        // 模拟参数
        let orbitRadiusFactor = 2;   // 轨道半径倍数（相对于地球半径）
        let angle = 0;                // 卫星当前角度
        const earthRadius = 18;       // 地球在画布上的半径（像素）
        const animationSpeed = 0.01;  // 动画速度因子
        
        // 创建星空背景
        function createStars() {
            const stars = document.getElementById('stars');
            stars.innerHTML = '';
            const starCount = 200;
            
            for (let i = 0; i < starCount; i++) {
                const star = document.createElement('div');
                star.classList.add('star');
                
                // 随机位置
                const left = Math.random() * 100;
                const top = Math.random() * 100;
                
                // 随机大小和透明度
                const size = Math.random() * 2;
                const opacity = 0.5 + Math.random() * 0.5;
                
                star.style.left = `${left}%`;
                star.style.top = `${top}%`;
                star.style.width = `${size}px`;
                star.style.height = `${size}px`;
                star.style.opacity = opacity;
                
                // 闪烁动画
                const duration = 2 + Math.random() * 3;
                star.style.animation = `twinkle ${duration}s infinite alternate`;
                
                stars.appendChild(star);
            }
        }
        
        // 添加星空样式
        const style = document.createElement('style');
        style.textContent = `
            @keyframes twinkle {
                0% { opacity: 0.2; }
                100% { opacity: 1; }
            }
        `;
        document.head.appendChild(style);
        
        // 初始化星空
        createStars();
        
        // 绘制地球和卫星
        function draw() {
            // 清除画布
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            
            // 计算中心点
            const centerX = canvas.width / 2;
            const centerY = canvas.height / 2;
            
            // 绘制星空背景
            ctx.fillStyle = '#0a1929';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            
            // 绘制轨道
            const orbitRadius = orbitRadiusFactor * earthRadius;
            ctx.beginPath();
            ctx.arc(centerX, centerY, orbitRadius, 0, Math.PI * 2);
            ctx.strokeStyle = 'rgba(0, 195, 255, 0.3)';
            ctx.lineWidth = 1;
            ctx.stroke();

            // 同步轨道
            ctx.setLineDash([5, 3]);
            ctx.beginPath();
            ctx.arc(centerX, centerY, 6.6*earthRadius, 0, Math.PI * 2);
            ctx.strokeStyle = 'rgba(255, 70, 70, 0.3)';
            ctx.lineWidth = 1;
            ctx.stroke();
            ctx.setLineDash([]);
            
            ctx.font = '20px Arial';
            ctx.fillStyle = 'rgba(255, 70, 70, 0.3)';
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.fillText('同步轨道',centerX+6.6*earthRadius,centerY);
            
            // 绘制地球
            ctx.font = `${2*earthRadius}px Arial`;
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.fillStyle = 'rgba(255, 255, 255, 1.0)';
            ctx.fillText('🌏',centerX,centerY+0.1*earthRadius);
            
            
            //const gradient = ctx.createRadialGradient(
            //    centerX, centerY, 0,
            //    centerX, centerY, earthRadius
            //);
            //gradient.addColorStop(0, '#2a8bf2');
            //gradient.addColorStop(1, '#0a5a9e');
            //
            //ctx.beginPath();
            //ctx.arc(centerX, centerY, earthRadius, 0, Math.PI * 2);
            //ctx.fillStyle = gradient;
            //ctx.fill();
            //
            //// 添加地球纹理
            //ctx.beginPath();
            //ctx.arc(centerX, centerY, earthRadius, 0, Math.PI * 2);
            //ctx.strokeStyle = 'rgba(255, 255, 255, 0.1)';
            //ctx.lineWidth = 1;
            //ctx.stroke();
            //
            //// 绘制云层
            //ctx.beginPath();
            //ctx.arc(centerX - 10, centerY - 10, earthRadius * 0.6, 0, Math.PI * 2);
            //ctx.fillStyle = 'rgba(255, 255, 255, 0.1)';
            //ctx.fill();
            //
            //ctx.beginPath();
            //ctx.arc(centerX + 15, centerY + 5, earthRadius * 0.4, 0, Math.PI * 2);
            //ctx.fillStyle = 'rgba(255, 255, 255, 0.1)';
            //ctx.fill();
            
            // 计算卫星位置
            const satelliteX = centerX + orbitRadius * Math.cos(angle);
            const satelliteY = centerY + orbitRadius * Math.sin(angle);
            
            // 绘制卫星
            ctx.font = `${earthRadius}px Arial`;
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.fillStyle = 'rgba(255, 255, 255, 1.0)';
            ctx.fillText('🛰️',satelliteX,satelliteY);
            
            //ctx.beginPath();
            //ctx.arc(satelliteX, satelliteY, 8, 0, Math.PI * 2);
            //const satGradient = ctx.createRadialGradient(
            //    satelliteX, satelliteY, 0,
            //    satelliteX, satelliteY, 8
            //);
            //satGradient.addColorStop(0, '#ffffff');
            //satGradient.addColorStop(1, '#a0a0a0');
            //ctx.fillStyle = satGradient;
            //ctx.fill();
            //
            //// 绘制卫星太阳能板
            //ctx.fillStyle = '#4facfe';
            //ctx.fillRect(satelliteX - 12, satelliteY - 2, 24, 4);
            //ctx.fillRect(satelliteX - 2, satelliteY - 12, 4, 24);
            
            // 绘制卫星到地球的连线
            ctx.beginPath();
            ctx.moveTo(centerX, centerY);
            ctx.lineTo(satelliteX, satelliteY);
            ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
            ctx.lineWidth = 1;
            ctx.stroke();
            
            // 角速度
            const w = 5/Math.sqrt(orbitRadius*orbitRadius*orbitRadius)
            
            // 绘制速度矢量      
            const velocityLength = 20*w*orbitRadius;
            const velocityX = -velocityLength * Math.sin(angle);
            const velocityY = +velocityLength * Math.cos(angle);
            
            ctx.beginPath();
            ctx.moveTo(satelliteX, satelliteY);
            ctx.lineTo(satelliteX + velocityX, satelliteY + velocityY);
            ctx.strokeStyle = '#ff6b6b';
            ctx.lineWidth = 2;
            ctx.stroke();
            
            // 绘制速度箭头
            drawArrow(ctx, satelliteX, satelliteY, satelliteX + velocityX, satelliteY + velocityY, 8, '#ff6b6b');
            
            // 引力
            const FLength = 25/(orbitRadiusFactor*orbitRadiusFactor);
            const Fx = -FLength*Math.cos(angle);
            const Fy = -FLength*Math.sin(angle);
            
            ctx.beginPath();
            ctx.moveTo(satelliteX, satelliteY);
            ctx.lineTo(satelliteX + Fx, satelliteY + Fy);
            ctx.strokeStyle = '#00FF00';
            ctx.lineWidth = 2;
            ctx.stroke();
            
            drawArrow(ctx, satelliteX, satelliteY, satelliteX + Fx, satelliteY + Fy, 8, '#00FF00');
            
            // 更新角度
            angle += w;
            if (angle > Math.PI * 2) 
            {
                angle -= Math.PI * 2;
            }
            
            // 循环动画
            requestAnimationFrame(draw);
        }
        
        // 绘制箭头函数
        function drawArrow(ctx, fromX, fromY, toX, toY, headLength, color) {
            const angle = Math.atan2(toY - fromY, toX - fromX);
            
            // 绘制箭头头部
            ctx.beginPath();
            ctx.moveTo(toX, toY);
            ctx.lineTo(
                toX - headLength * Math.cos(angle - Math.PI / 6),
                toY - headLength * Math.sin(angle - Math.PI / 6)
            );
            ctx.lineTo(
                toX - headLength * Math.cos(angle + Math.PI / 6),
                toY - headLength * Math.sin(angle + Math.PI / 6)
            );
            ctx.closePath();
            ctx.fillStyle = color;
            ctx.fill();
        }
        
        // 计算轨道速度
        function calculateOrbitalVelocity(radiusFactor) {
            const R = radiusFactor * R_earth; // 轨道半径（km）
            return Math.sqrt(GM / R); // 速度（km/s）
        }
        
        // 计算轨道周期
        function calculateOrbitalPeriod(radiusFactor) {
            const R = radiusFactor * R_earth; // 轨道半径（km）
            const v = calculateOrbitalVelocity(radiusFactor); // 速度（km/s）
            return (2 * Math.PI * R) / v; // 周期（s）
        }
        
        // 更新显示值
        function updateValues() {
            // 计算轨道高度（千米）
            const altitude = (orbitRadiusFactor) * R_earth;
            document.getElementById('altitudeValue').textContent = altitude.toFixed(0) + ' km';
            document.getElementById('radiusValue2').textContent = orbitRadiusFactor.toFixed(1);
            
            // 计算轨道速度（千米/秒）
            const velocity = calculateOrbitalVelocity(orbitRadiusFactor);
            document.getElementById('velocity').textContent = velocity.toFixed(2);
            
            // 计算轨道周期（小时）
            const period = calculateOrbitalPeriod(orbitRadiusFactor) / 3600;
            document.getElementById('period').textContent = period.toFixed(2);
        }
        
        // 滑块事件监听
        document.getElementById('radiusSlider').addEventListener('input', function() {
            orbitRadiusFactor = parseFloat(this.value);
            updateValues();
        });
        
        // 初始更新
        updateValues();
        
        // 启动动画
        draw();
    </script>
</body>
</html>
